// rem 动态计算函数
export function setRem() {
  const baseWidth = 1920
  const baseFontSize = 16
  const scale = window.innerWidth / baseWidth
  document.documentElement.style.fontSize = baseFontSize * scale + 'px'
}

let resizeTimer: number | null = null

export function handleResize() {
  if (resizeTimer) {
    cancelAnimationFrame(resizeTimer)
  }
  resizeTimer = requestAnimationFrame(() => {
    setRem()
  })
}

// 初始化rem设置
export function initRem() {
  setRem()
  window.addEventListener('resize', handleResize)
}

// 清理rem设置
export function destroyRem() {
  window.removeEventListener('resize', handleResize)
  if (resizeTimer) {
    cancelAnimationFrame(resizeTimer)
    resizeTimer = null
  }
}
